import { defineStore } from 'pinia';
import { computed, reactive, ref } from 'vue';

// export const useCounterStore = defineStore('counter', {
// state: () => ({
//   count: 0,
// }),
// actions: {
//   increment() {
//     this.count++;
//   },
// },
// getters: {
//   doubleCount: (state) => state.count * 2,
// }
// }); 
// 以下是setup形式
export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)

  const person = reactive({
    name: '张三',
    age: 18
  })
  function increment() {
    count.value++
    console.log('person.age :>> ', count.value);

  }

  function incrementPersonAge() {
    person.age++
    console.log('person.age :>> ', person.age);
  }

  const doubleCount = computed(() => count.value * 2)


  return { count, increment, doubleCount, person, incrementPersonAge }


}, {
  persist: true
})